package com.ruoyi.job.task;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.ruoyi.common.core.domain.OaResult;
import com.ruoyi.common.core.utils.facade.OaBusinessFacade;
import com.ruoyi.job.domain.OaRecruit;
import com.ruoyi.job.service.IOaRecruitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.ruoyi.common.core.utils.StringUtils;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * 定时任务调度测试
 * 
 * @author ruoyi
 */
@Component("ryTask")
public class RyTask
{
    @Autowired
    private IOaRecruitService oaRecruitService;


    public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i)
    {
        System.out.println(StringUtils.format("执行多参方法： 字符串类型{}，布尔类型{}，长整型{}，浮点型{}，整形{}", s, b, l, d, i));
    }

    public void ryParams(String params)
    {
        System.out.println("执行有参方法：" + params);
    }

    public void ryNoParams()
    {
        System.out.println("执行无参方法");
    }

    public void getRecruitRequestTask(){
        //System.out.println("执行获取招聘需求任务");
        OaResult result= OaBusinessFacade.getRecruitRequest();
       // System.out.println(JSON.toJSONString(result));
        if("200".equals(result.getCode())){
            OaRecruit where=new OaRecruit();
            List<OaRecruit> oaRecruitList= JSON.parseObject(result.getData(), new TypeReference<List<OaRecruit>>() {});
            for (OaRecruit oaRecruit:oaRecruitList){
                where.setProcessCode(oaRecruit.getProcessCode());
                List<OaRecruit> list=oaRecruitService.selectOaRecruitList(where);
                if(CollectionUtils.isEmpty(list)){
                    oaRecruit.setCode(result.getCode());
                    oaRecruit.setMessage(result.getMessage());
                    oaRecruitService.insertOaRecruit(oaRecruit);
                }
            }
        }else if("400".equals(result.getCode())){
            OaRecruit where=new OaRecruit();
            List<OaRecruit> oaRecruitList= JSON.parseObject(result.getData(), new TypeReference<List<OaRecruit>>() {});
            for (OaRecruit oaRecruit:oaRecruitList){
                where.setProcessCode(oaRecruit.getProcessCode());
                List<OaRecruit> list=oaRecruitService.selectOaRecruitList(where);
                if(!CollectionUtils.isEmpty(list)){
                    oaRecruit.setCode(result.getCode());
                    oaRecruit.setMessage(result.getMessage());
                    oaRecruitService.updateOaRecruit(oaRecruit);
                }
            }
        }
    }

}
